package LCR剑指.LCR098;

class Solution {
    public static int uniquePaths(int m, int n, int[][] flgs) {
        /**
         * 1.dp数组定义，dp是到当前点的路径树量
         * 2.递归公式
         * 3.初始化
         * 4.遍历顺序
         */
        int[][] dp = new int[m][n];
        for (int i = 0; i < n; i++) {
            if (flgs[0][i] == 1) {
                dp[0][i] = 0;
                while(i<n) dp[0][i++]=0 ;
                break;
            }
            dp[0][i] = 1;
        }
        for (int i = 0; i < m; i++) {
            if (flgs[i][0] == 1) {
                dp[i][0] = 0;
                while(i<n) dp[i++][0]=0 ;
                break;
            }
            dp[i][0] = 1;
        }
        //从第二行开始遍历
        for (int i = 1; i < m; i++) {
            for (int j = 1; j < n; j++) {
                if (flgs[i][j] == 1) {
                    dp[i][j] = 0;
                }else {
                    dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
                }
            }
        }
        return dp[m - 1][n - 1];
    }

    public static void main(String[] args) {
        int i = uniquePaths(4, 7, new int[][]{{0, 0, 0, 1, 0, 0, 0,0}, {0, 0, 0, 0, 0, 0, 0,0}, {0, 0, 0, 1, 0, 0, 0,0},{0, 0, 0, 0, 0, 0, 0,0}});
        System.out.printf(i+"");
    }
}